package com.xdjd.mobile.business.api.clock;

import com.gitee.easyopen.annotation.Api;
import com.gitee.easyopen.annotation.ApiService;
import com.gitee.easyopen.doc.DataType;
import com.gitee.easyopen.doc.annotation.ApiDoc;
import com.gitee.easyopen.doc.annotation.ApiDocField;
import com.gitee.easyopen.doc.annotation.ApiDocMethod;
import com.xdjd.mobile.business.api.BaseApi;
import com.xdjd.mobile.business.constant.ExistClockStatus;
import com.xdjd.mobile.business.entity.param.BasePageParam;
import com.xdjd.mobile.business.entity.param.clock.AddClockBonusParam;
import com.xdjd.mobile.business.entity.param.clock.BaseClockParam;
import com.xdjd.mobile.business.entity.param.clock.CreateClockParam;
import com.xdjd.mobile.business.entity.result.BasePageResult;
import com.xdjd.mobile.business.entity.result.alipay.AlipayTradeAppPayVo;
import com.xdjd.mobile.business.entity.result.clock.CheckBaseResult;
import com.xdjd.mobile.business.entity.result.clock.CheckClockRecordResult;
import com.xdjd.mobile.business.entity.result.clock.ClockRecordResult;
import com.xdjd.mobile.business.entity.result.clock.CreateClockResult;
import com.xdjd.mobile.business.entity.vo.*;
import com.xdjd.mobile.business.service.ClockService;
import com.xdjd.mobile.system.ApiUtil;
import com.xdjd.mobile.system.anotations.ApiAuth;
import net.oschina.durcframework.easymybatis.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by Administrator on 2019/1/10 0010.
 */
@ApiService
@ApiDoc("用户打卡")
public class ClockApi extends BaseApi {

    @Autowired
    private ClockService clockService;

    @Api(name = "user.clock.create")
    @ApiDocMethod(description = "用户创建打卡记录")
    public CreateClockResult createClock(CreateClockParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        return clockService.createClock(param, currentUser.getId());
    }

    @Api(name = "user.clock.add.bonus")
    @ApiDocMethod(description = "用户追加激励金")
    public AlipayTradeAppPayVo addClockBonus(AddClockBonusParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        return clockService.addClockBonus(param, currentUser.getId());
    }


    @Api(name = "clock.detail")
    @ApiDocMethod(description = "打卡详情")
    public CheckClockRecordResult clockDetail(BaseClockParam param) {
        return clockService.clockDetail(param.getClockNo());
    }

    @Api(name = "clock.supervise.list")
    @ApiDocMethod(description = "监督者列表(别人监督我)", results = {
            @ApiDocField(name = "totalNum", description = "总记录数", example = "100",dataType = DataType.LONG),
            @ApiDocField(name = "infos", description = "数据", elementClass = LockSuperviseListVO.class)})
    public BasePageResult<LockSuperviseListVO> lockSuperviseList(BasePageParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        return clockService.lockSuperviseList(currentUser.getId(), param);
    }

    @Api(name = "clock.list")
    @ApiDocMethod(description = "打卡者列表(我监督别人)", results = {
            @ApiDocField(name = "totalNum", description = "总记录数", example = "100",dataType = DataType.LONG),
            @ApiDocField(name = "infos", description = "数据", elementClass = LockListVO.class)})
    public BasePageResult<LockListVO> lockList(BasePageParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        return clockService.lockList(currentUser.getId(), param);
    }

    @Api(name = "clock.record.get")
    @ApiDocMethod(description = "我的打卡记录列表", results = {@ApiDocField(name = "pageIndex", description = "第几页", dataType = DataType.INT, example = "1"),
            @ApiDocField(name = "pageSize", description = "每页几条数据", dataType = DataType.INT, example = "2"),
            @ApiDocField(name = "total", description = "总记录数", dataType = DataType.LONG, example = "100"),
            @ApiDocField(name = "list", description = "数据", dataType = DataType.ARRAY, elementClass = ClockRecordResult.class),})
    public PageInfo<ClockRecordResult> getClockRecordList(BasePageParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        return clockService.getClockRecordList(param, currentUser.getId());
    }


    @Api(name = "nologin.check.clock.record")
    @ApiDocMethod(description = "查询是否有进行中的打卡记录")
    public CheckBaseResult checkClockRecord() {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        if (currentUser == null) {
            CheckBaseResult recordResult = new CheckBaseResult();
            recordResult.setExistStatus(ExistClockStatus.not_exist.getCode().byteValue());
        }
        return clockService.checkClockRecord(currentUser.getId());
    }


    @Api(name = "clock.record.list")
    @ApiDocMethod(description = "获取打卡记录列表")
    public ClockRecordListResult clockRecordList(BaseClockParam param) {

        return clockService.clockRecordList(param.getClockNo());

    }

}
